//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo60AND80;

import java.util.HashSet;
import java.util.Set;

public class demo_73 {
    public demo_73() {
    }

    public static void main(String[] args) {
        int[][] matrix = new int[][]{{0, 1, 2, 0}, {3, 4, 5, 2}, {1, 3, 1, 5}};
        setZeroes(matrix);

        for(int[] ints : matrix) {
            for(int anInt : ints) {
                System.out.println(anInt);
            }
        }

    }

    public static void setZeroes(int[][] matrix) {
        Set<Integer> row = new HashSet();
        Set<Integer> col = new HashSet();

        for(int x = 0; x < matrix.length; ++x) {
            for(int y = 0; y < matrix[0].length; ++y) {
                if (matrix[x][y] == 0) {
                    row.add(x);
                    col.add(y);
                }
            }
        }

        for(Integer x : row) {
            for(int y = 0; y < matrix[x].length; ++y) {
                matrix[x][y] = 0;
            }
        }

        for(Integer y : col) {
            for(int x = 0; x < matrix.length; ++x) {
                matrix[x][y] = 0;
            }
        }

    }

    public static void setZeroes2(int[][] matrix) {
        int row = matrix.length;
        int col = matrix[0].length;
        boolean row0_flag = false;
        boolean col0_flag = false;

        for(int j = 0; j < col; ++j) {
            if (matrix[0][j] == 0) {
                row0_flag = true;
                break;
            }
        }

        for(int i = 0; i < row; ++i) {
            if (matrix[i][0] == 0) {
                col0_flag = true;
                break;
            }
        }

        for(int i = 1; i < row; ++i) {
            for(int j = 1; j < col; ++j) {
                if (matrix[i][j] == 0) {
                    matrix[i][0] = matrix[0][j] = 0;
                }
            }
        }

        for(int i = 1; i < row; ++i) {
            for(int j = 1; j < col; ++j) {
                if (matrix[i][0] == 0 || matrix[0][j] == 0) {
                    matrix[i][j] = 0;
                }
            }
        }

        if (row0_flag) {
            for(int j = 0; j < col; ++j) {
                matrix[0][j] = 0;
            }
        }

        if (col0_flag) {
            for(int i = 0; i < row; ++i) {
                matrix[i][0] = 0;
            }
        }

    }
}
